#include "sys_config.h"

void Dev_Control_Tack(void)
{
    SSD1306_CLS();
    while(1)
    {
        uint16_t psData = 0; 
        int ret;
        //获取温度\湿度
        ret = SHT20_ReadData(&globals_dev_status.temperature, &globals_dev_status.humidity); 
        if (ret != 0)
        {
            printf("SHT20_ReadData error\n");
        }
        //获取红外\光照
        ret = AP3216C_ReadData(&globals_dev_status.infrared, &globals_dev_status.light, &psData);
        if (ret != 0)
        {
            printf("AP3216C_ReadData error\n");
        }
        printf("temp: %f, hum :%f \n", globals_dev_status.temperature, globals_dev_status.humidity);
        printf("infrared: %d, light :%d \n", globals_dev_status.infrared, globals_dev_status.light);
        printf("light: %d, beep: %d, fan: %d \n", globals_dev_status.lamp_state.lamp_power, globals_dev_status.beep_state.beep_power, globals_dev_status.fan_state.fan_power);
        printf("R: %d, G: %, B: %d\n", globals_dev_status.lamp_state.RGB_color_r, globals_dev_status.lamp_state.RGB_color_g, globals_dev_status.lamp_state.RGB_color_b);
        set_fan((globals_dev_status.fan_state.fan_power == POWER_STATUS_ON));
        set_buzzer((globals_dev_status.beep_state.beep_power == POWER_STATUS_ON));
        set_led((globals_dev_status.lamp_state.lamp_power == POWER_STATUS_ON));

        if (globals_dev_status.lamp_state.lamp_power == POWER_STATUS_ON)
        {
            if ((globals_dev_status.lamp_state.RGB_color_r == 0) && (globals_dev_status.lamp_state.RGB_color_g == 0) && (globals_dev_status.lamp_state.RGB_color_b == 0))
            {
                AW2013_Control_RGB(255,255,255);
            }
            else{
                AW2013_Control_RGB(globals_dev_status.lamp_state.RGB_color_r, globals_dev_status.lamp_state.RGB_color_g, globals_dev_status.lamp_state.RGB_color_b);
            }
        }
        else
        {
            AW2013_Control_RGB(0,0,0);
        }
        
        show_oled();
        usleep(1000*1000);
    }

}